import type { MesPackageRule, MesPackageRuleMaterial, MesPackageRuleTier } from "@/pages/mes/packageRule/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //规则编码
  code?: string;
  //规则名称
  name?: string;
  //规则类型
  type?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: MesPackageRule[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/mes/package/rule/pageList",
    data
});
const getInfo = (id: React.Key): Promise<MesPackageRule> =>
  apiClient.get({
    url: `/mes/package/rule/${id}`
});

const add = (data: MesPackageRule): Promise<MesPackageRule> =>
  apiClient.post({
    url: "/mes/package/rule",
    data
});

const update = (data: MesPackageRule): Promise<MesPackageRule> =>
  apiClient.put({
    url: "/mes/package/rule",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/mes/package/rule",
    params: {
    ids: ids.join(",")
  }
});
const getMaterials = (id: React.Key): Promise<MesPackageRuleMaterial[]> =>
  apiClient.post({
    url: "/mes/package/rule/material/list",
    data: {
      ruleId: id
    }
  });

const getTiers = (id: React.Key): Promise<MesPackageRuleTier[]> =>
  apiClient.post({
    url: "/mes/package/rule/tier/list",
    data: {
      ruleId: id
    }
  });

export const mesPackageRuleService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  getMaterials,
  getTiers,
};

export default mesPackageRuleService;